/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package load.parent;

import core.DispatcherPort;
import core.InPort;
import core.StdNode;
import core.TriggerPort;

/**
 *
 * @author Ben
 */
public abstract class SmartCompare extends StdNode{
    protected DispatcherPort resChanged = new DispatcherPort();
    private TriggerPort argChanged = new TriggerPort() {
        @Override
        protected void callInternal() {
            resChanged.callTargets();
        }
    };
    private InPort arg1 = new InPort(java.lang.Object.class, argChanged);
    private InPort arg2 = new InPort(java.lang.Object.class, argChanged);

    protected int compare(){
        int result = 0;
        if(arg1.getValue().getClass().getSimpleName().equals(
           arg2.getValue().getClass().getSimpleName())){
              if(arg1.getValue().getClass().isAssignableFrom(Double.class)){
                result =  ((Double)arg1.getValue()).compareTo((Double)arg2.getValue());
              }else if(arg1.getValue().getClass().isAssignableFrom(Integer.class)){
                result =  ((Integer)arg1.getValue()).compareTo((Integer)arg2.getValue());
              }else if(arg1.getValue().getClass().isAssignableFrom(String.class)){
                result =  ((String)arg1.getValue()).compareTo((String)arg2.getValue());
              }else if(arg1.getValue().getClass().isAssignableFrom(Boolean.class)){
                result =  ((Boolean)arg1.getValue()).compareTo((Boolean)arg2.getValue());
              }
        }
        return result;
    }

    public SmartCompare() {
         this.putPort("arg1", arg1);
         this.putPort("arg2", arg2);
         this.putPort("resChanged", resChanged);
         this.putPort("argChanged",argChanged);
    }

}
